package 多态.instrumentExample;



/**
 * 协变量返回
 */
public class CovariantReturnType {
	public static void main(String[] args) {
		Mill mill = new Mill();
		WheatMill wheatMill = new WheatMill();
		// 正常来说，返回了啥，就是啥
		Grain grain = mill.process();
		Wheat wheat = wheatMill.process();
		// 但是对于javase5之后，协变量返回，可以向上转型，返回父类。
		Grain grain1 = wheatMill.process();
	}
}

class Grain {
	@Override
	public String toString() {
		return "Grain{}";
	}
}

class Wheat extends Grain {
	@Override
	public String toString() {
		return "wheat";
	}
}

class Mill {
	Grain process() {
		return new Grain();
	}
}

class WheatMill extends Mill {
	@Override
	Wheat process() {
		return new Wheat();
	}
}
